home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 699 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.2 KB

  1. Path: tank.news.pipex.net!pipex!oleane!epita!photon!denis_r
  2. From: denis_r@epita.fr (Frank DENIS (Jedi/Sector One))
  3. Newsgroups: comp.std.c
  4. Subject: Re: int main(void) or int main()?
  5. Date: 5 Apr 1996 12:46:27 GMT
  6. Organization: Epita (French engineering school)
  7. Distribution: world
  8. Message-ID: <4k34n3$qvt@boson.epita.fr>
  9. References: <4k17gf$gob@isoit109.bbn.hp.com>
  10. NNTP-Posting-Host: photon.epita.fr
  11. Function: KrAzY k0dEr
  12. X-newsreader: XRN SunLight
  13.  
  14.  
  15. In article <4k17gf$gob@isoit109.bbn.hp.com>, Bruno RICHARD <bruno_richard@hp-france-om1.om.hp.com> writes:
  16.  
  17. -=)> What is the recommended declaration for a function that does
  18. -=)> not take arguments and does not return anything:
  19. -=)>    void myfunc();
  20. -=)> or
  21. -=)>    void myfunc(void);
  22.  
  23. The second one is definitely better, as the first one as different
  24. meanings according to the C style you're conforming to :
  25.  
  26. - In K&R, () means "gimme anything as parameters, I won't care"
  27. - In ANSI C, it should be avoided
  28. - In ANSI C++, it means "this functions takes NOTHING"
  29.  
  30. As K&R is a bit obsolete and the (void) notation works in ANSI C as
  31. well as C++, you'd better use this form that is BTW more explicit than
  32. nothing and should be interpreted the same way by any modern C
  33. compiler.
  34.  
  35. -=)> I remember that few years ago on Turbo C 2.0 the second form was better
  36. -=)> optimized. So I got used to do so, but I just read the C FAQ and noticed
  37. -=)> that there was some argument about main() returning int or void,
  38.  
  39. main returns an INT and takes zero or two arguments. Nothing else.
  40. But well, Turbo C is pretty lame to produce a less efficient code in the
  41. second case anyway. Use DJGPP, it rocks ! Your code will be at least 3 times
  42. faster than with Turbo C ( Turbo, eh eh... ) and GCC is a bit more ISO 9899
  43. conformant than Borland shits.
  44.  
  45. -=)> and
  46. -=)> I am wondering whether there could be some portability problems around.
  47. -=)> -bruno
  48.  
  49. Best regards, Frank.
  50. -- 
  51. .-=)>       Frank DENIS aka JEDI from SECTOR ONE ( j@nether.net )        <(=-. 
  52. \   Serveur minitel RTC-One au prix d'une simple communication sur Paris :   /
  53.  )  (1) 48.70.10.29 ou (1) 48.58.46.17 - Messagerie, HP48, PC, delires, ... (
  54. (   Acces 28800 bauds au (1) 49.88.76.91 . Informations: email j@nether.net  )
  55.  \_-^-_.                   Mon pere est un vieux con                  ._-^-_/
  56.